package cn.itcast.spring.demo2.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;

import cn.itcast.spring.demo2.dao.AccountDao;

@Service
public class AccountServiceImpl implements AccountService {

	@Autowired
	private AccountDao accountDao;
	
	
	@Autowired
	private TransactionTemplate transactionTemplate;
	
	
	@Override
	public void transferMoney(String from, String to, double money) {
		transactionTemplate.execute(new TransactionCallbackWithoutResult() {
			@Override
			protected void doInTransactionWithoutResult(TransactionStatus status) {
				accountDao.moneyOut(from,money);
				System.out.println(1/0);
				accountDao.moneyIn(to,money);
			}
		});
		
		
	}


}
